﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class FormlaySprinklerBasement : HYBaseForm
	{
		public FormlaySprinklerBasement(Autodesk.Revit.DB.Document d)
		{
			this.doc = d;
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.Init();
		}

		private void Init()
		{
			base.Icon = Resource.YArchitechIcon;
			this.txtElev.Text = this.layParameter.Elevation.ToString();
			this.txtRadius.Text = this.layParameter.Radius.ToString();
			if (this.layParameter.LinkType == 1)
			{
				this.radioLevel.Checked = true;
			}
			else if (this.layParameter.LinkType == 2)
			{
				this.radioVer.Checked = true;
			}
			else
			{
				this.radioNo.Checked = true;
			}
			this.hyTextBox1.Text = this.layParameter.Distance.ToString();
			if (this.layParameter.SelectType == 1)
			{
				this.radioButton2.Checked = true;
			}
			else
			{
				this.radioButton1.Checked = true;
			}
			this.layParameter.PiptType = 0;
			int num = 0;
			foreach (Element element in YJKElementFilter.GetElementByClass(typeof(PipeType), this.doc))
			{
				this.comboBox1.Items.Add(element.Name);
				if (this.layParameter.PiptTypeName == element.Name)
				{
					this.layParameter.PiptType = num;
				}
				num++;
			}
			this.comboBox1.SelectedIndex = this.layParameter.PiptType;
			if (this.layParameter.nSign == 1)
			{
				this.cbSign.Checked = true;
				return;
			}
			this.cbSign.Checked = false;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			try
			{
				this.layParameter.Elevation = Convert.ToDouble(this.txtElev.Text);
				this.layParameter.Radius = Convert.ToDouble(this.txtRadius.Text);
				if (this.radioLevel.Checked)
				{
					this.layParameter.LinkType = 1;
				}
				else if (this.radioVer.Checked)
				{
					this.layParameter.LinkType = 2;
				}
				else
				{
					this.layParameter.LinkType = 3;
				}
				this.layParameter.PiptType = this.comboBox1.SelectedIndex;
				this.layParameter.PiptTypeName = this.comboBox1.Text;
				this.layParameter.Distance = Convert.ToDouble(this.hyTextBox1.Text);
				if (this.radioButton2.Checked)
				{
					this.layParameter.SelectType = 1;
				}
				else
				{
					this.layParameter.SelectType = 2;
				}
				if (this.cbSign.Checked)
				{
					this.layParameter.nSign = 1;
				}
				else
				{
					this.layParameter.nSign = 0;
				}
			}
			catch
			{
				MessageBox.Show("参数不正确!", "盈建科提示");
				return;
			}
			this.layParameter.Save();
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
			base.Close();
		}

		private void cbSign_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbSign.Checked)
			{
				this.blSign = true;
				return;
			}
			this.blSign = false;
		}

		private Document doc;

		public LayBasementSprinklerParameter layParameter = new LayBasementSprinklerParameter();

		public bool blSign;
	}
}
